package com.atguigu.java8.streamPractice;

import com.atguigu.java8.lambdaDemo.Employee;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author Xiaohong X Gou
 * @createTime 2022-10-12 11:05
 * @description
 */
public class TestStreamAPI {
    @Test
    public void test1(){
        Integer[] nums =new Integer[]{1,2,3,4,5};
        Arrays.stream(nums)
                .map(e->e*e)
                .forEach(System.out::println);
    }
    List<Employee> emps = Arrays.asList(
            new Employee(1,"张三",18,9999.99, Employee.Status.FREE),
            new Employee(2,"李四",38,5555.99, Employee.Status.BUSY),
            new Employee(3,"王五",50,6666.66, Employee.Status.VOCATION),
            new Employee(4,"赵六",16,3333.33, Employee.Status.FREE),
            new Employee(5,"田七",12,8888.88, Employee.Status.BUSY)
    );
    @Test
    public void test2(){
        Optional<Integer> reduce = emps.stream()
                .map(e -> 1)
                .reduce(Integer::sum);
        System.out.println(reduce.get());

    }


}
